package cn.gson.springboot.model.service;

import cn.gson.springboot.model.dao.ApprovalRecordDao;
import cn.gson.springboot.model.mapper.ApprovalRecordMapper;
import cn.gson.springboot.model.pojos.ApprovalRecord;
import cn.gson.springboot.model.vo.ApprovalRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class ApprovalRecordService {
    @Autowired
    ApprovalRecordMapper appRecordMapper;
    @Autowired
    ApprovalRecordDao appRecordDao;

    public List<ApprovalRecord> selectAllAppRecordByQuoId(Integer quoId){
        return appRecordMapper.selectAllAppRecordByQuoId(quoId);
    }

    public ApprovalRecord selectAppRecordByQuoAppId(Integer quoId){
        return appRecordMapper.selectAppRecordByQuoAppId(quoId);
    }
    public List<ApprovalRecord> selectAllAppRecordByPurId(Integer purId){
        return appRecordMapper.selectAllAppRecordByPurId(purId);
    }

    public ApprovalRecord selectAppRecordByPurAppId(Integer purId){
        return appRecordMapper.selectAppRecordByPurAppId(purId);
    }

    public List<ApprovalRecord> selectAllAppRecordByBusId(Integer businessId){
        return appRecordMapper.selectAllAppRecordByBusId(businessId);
    }

    public ApprovalRecord selectAppRecordByBusAppId(Integer businessId){
        return appRecordMapper.selectAppRecordByBusAppId(businessId);
    }

    public List<ApprovalRecord> selectAllAppRecordByConId(Integer conId){
        return appRecordMapper.selectAllAppRecordByConId(conId);
    }

    public ApprovalRecord selectAppRecordByConAppId(Integer conId){
        return appRecordMapper.selectAppRecordByConAppId(conId);
    }

    public List<ApprovalRecord> selectAllAppRecordByPayId(Integer payId){
        return appRecordMapper.selectAllAppRecordByPayId(payId);
    }

    public ApprovalRecord selectAppRecordByPayAppId(Integer payId){
        return appRecordMapper.selectAppRecordByPayAppId(payId);
    }

    public void saveAppRecord(ApprovalRecordVo vo){
        ApprovalRecord app = new ApprovalRecord();
        app.setApprovalRecordId(vo.getApprovalRecordId());
        app.setEmployeeByApplicantEmpId(vo.getEmployeeByApplicantEmpId());// 1
        app.setApprovalRecordDate(vo.getApprovalRecordDate());//1
        app.setApprovalRecordOper(vo.getApprovalRecordOper());//2
        app.setEmployeeByApprovalEmpId(vo.getEmployeeByApprovalEmpId());//2
        app.setApprovalRecordNote(vo.getApprovalRecordNote());//2
        if ("1".equals(vo.getApprovalRecordTime())){
            app.setApprovalRecordTime(new Timestamp(System.currentTimeMillis()));
        }
        app.setQuotationByQuotationId(vo.getQuotationByQuotationId());
        app.setBusinesstripByBusinessId(vo.getBusinesstripByBusinessId());
        app.setPurchaseByPurchaseId(vo.getPurchaseByPurchaseId());
        app.setPaymentPlanByPaymentPlanId(vo.getPaymentPlanByPaymentPlanId());
        app.setContractByContractId(vo.getContractByContractId());
        appRecordDao.save(app);
    }

    public List<ApprovalRecord> selectAllAppRecordByContractId(Integer contractId){
        return appRecordMapper.selectAllAppRecordByContractId(contractId);
    }

}
